<?php
require_once('Smarty.class.php');
require_once('conf.inc.php');

class MySmarty extends Smarty{
	function MySmarty(){
		$this->Smarty();
		$this->template_dir = TEMPLATE_DIR;
		$this->compile_dir = COMPILE_DIR;
		$this->cache_dir = CACHE_DIR;
		$this->config_dir = CONFIG_DIR;
		$this->assign('app_name', 'DougaPJ');
		$this->compile_check  = true; 
	}
	
	function getNavigation($pageName,$page,$total,$tag_query){

		$totalPage = ceil($total/PAGE_SIZE);
		$base = BASE_URL."$pageName";
		$str = "";
	
		if($page>1) $str .= "<a class=\"button\" href=\"$base?page=".($page-1)."$tag_query\"><span>Prev</span></a> ";
		
		if($page  > 5 )  $str .="<a class=\"button\" href='$base?page=1$tag_query'><span>1</span></a>...";
		
		
		$start_page = $page -4 > 1 ?  $page-4: 1;
	
		$end_page = 1;
	
		if($totalPage>1) $end_page = $totalPage > $page+4  ?  $page+4: $totalPage;
	
		if($totalPage>1) $end_page = $end_page<8 && $totalPage>=8 ? 8 : $end_page;
		
	
		for($i=$start_page;$i<=$end_page;$i++){
	
			if($page != $i){
	
				$str .= "<a class=\"button\" href='$base?page=$i$tag_query'><span>$i</span></a>";
	
			}else{
	
				$str .= "<a class=\"button2\" href='#'><span>$i</span></a>";
	
			}
	
		}
	
		$next = $page + 1;
	
		if($page+4  < $totalPage) $str .= "...<a class=\"button\" href='$base?page=$totalPage$tag_query'><span>$totalPage</span></a> ";
		if($page< $totalPage) $str .="<a class=\"button\" href='$base?page=".($page+1)."$tag_query'><span>Next</span></a>";

		return $str;
	
	}
	
	
}

 ?>
